package com.biyao.service.model.base;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import java.util.HashMap;
import java.util.Map;

import com.biyao.schedulingdao.base.TWorkerMapper;
import com.biyao.schedulingentity.base.TRollerTypeEntity;
import com.biyao.schedulingentity.base.TWorkerEntity;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.ArrayList;
/**
 * 
 *
 * @author code generator
 * @date 2019-09-16 09:44:08
 */
@Service
public class TWorkerService extends ServiceImpl<TWorkerMapper, TWorkerEntity>{

    public Page list(int pageNum, int pageSize){

        EntityWrapper<TWorkerEntity> tWorkerentityWrapper=new EntityWrapper<>();
        Page page=selectPage(new Page(pageNum,pageSize),tWorkerentityWrapper);
        page.setRecords(formatRecords(page.getRecords()));
        return page;
    }

    List formatRecords(List<TWorkerEntity> list){
        List resList=new ArrayList();
        for(TWorkerEntity tWorkerEntity:list){
            Map map=formatEntity(tWorkerEntity);
            resList.add(map);
        }
        return resList;
    }

    Map formatEntity(TWorkerEntity tWorkerEntity){
        Map map=new HashMap(16);
        //员工信息
        if(tWorkerEntity.getId()!=null){
           map.put("id",tWorkerEntity.getId());
        }
        //员工代号
        if(tWorkerEntity.getWorkerCode()!=null){
           map.put("workerCode",tWorkerEntity.getWorkerCode());
        }
        //员工姓名
        if(tWorkerEntity.getWorkerName()!=null){
           map.put("workerName",tWorkerEntity.getWorkerName());
        }
        //工种id
        if(tWorkerEntity.getWorkerType()!=null){
           map.put("workerTypeId",tWorkerEntity.getWorkerType());
        }
        //身份证
        if(tWorkerEntity.getIdCard()!=null){
           map.put("idCard",tWorkerEntity.getIdCard());
        }
        //手机号
        if(tWorkerEntity.getTel()!=null){
           map.put("tel",tWorkerEntity.getTel());
        }
        //邮箱
        if(tWorkerEntity.getEmail()!=null){
           map.put("email",tWorkerEntity.getEmail());
        }
        //
        if(tWorkerEntity.getRemark()!=null){
           map.put("remark",tWorkerEntity.getRemark());
        }
        //
        if(tWorkerEntity.getCreateTime()!=null){
           map.put("createTime",tWorkerEntity.getCreateTime());
        }
        //
        if(tWorkerEntity.getUpdateTime()!=null){
           map.put("updateTime",tWorkerEntity.getUpdateTime());
        }
        //
        if(tWorkerEntity.getCreateBy()!=null){
           map.put("createBy",tWorkerEntity.getCreateBy());
        }
        //
        if(tWorkerEntity.getUpdateBy()!=null){
           map.put("updateBy",tWorkerEntity.getUpdateBy());
        }
        return map;
    }

    public Boolean selectCodeIsRepeat(String code) {
        EntityWrapper<TWorkerEntity> tRollerMaterialEntityEntityWrapper=new EntityWrapper<>();
        tRollerMaterialEntityEntityWrapper.eq("worker_code",code);
        List<TWorkerEntity> list=selectList(tRollerMaterialEntityEntityWrapper);
        if(list.size()>0){
            return true;
        }
        return false;
    }

    public Boolean selectUpdateCodeIsRepeat(String code,Integer id) {
        EntityWrapper<TWorkerEntity> tRollerMaterialEntityEntityWrapper=new EntityWrapper<>();
        tRollerMaterialEntityEntityWrapper.eq("worker_code",code);
        List<TWorkerEntity> list=selectList(tRollerMaterialEntityEntityWrapper);
        if(list.size()>0){
            if(list.get(0).getId().intValue()!=id.intValue()){
                return true;
            }
            return false;
        }
        return false;
    }

}

